#include "server.h"
#include <stdlib.h>

void			add_in_list(t_player *list, t_player *to_add)
{
   t_player		*tmp;

   tmp = list;
   if (!tmp)
   {
      tmp = to_add;
      to_add->next = 0;
   }
   else
   {
      while (tmp && tmp->next && (tmp->next->id < to_add->id))
	 tmp = tmp->next;
      to_add->next = tmp->next;
      tmp->next = to_add;
   }
}

t_player			*remove_from_list(t_player *list, t_player *to_del)
{
  t_player		*tmp;

  tmp = list;
  if (tmp->id == to_del->id)
    {
      list = list->next;
      return (list);
    }
  while (tmp && tmp->next && (tmp->next->id != to_del->id))
    tmp = tmp->next;
  if (tmp->next == NULL)
    return (NULL);
  tmp->next = tmp->next->next;
  return (tmp->next);
}

t_player			*get_player_from_list(t_player *list, pid_t to_find)
{
  t_player		*tmp;

  tmp = list;
  while (tmp && (tmp->id != to_find))
    tmp = tmp->next;
  return (tmp);
}
